<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="lib/vue.global.js"></script>
</head>
<body>
  <div id="root">
    <h1>App</h1>
    <my-layout></my-layout>
  </div>
</body>
<template id="main">
  <div>
    <h3>main</h3>
    {{ msg }} - {{ num }} - {{ reactiveNum }}
  </div>
</template>
<template id="layout">
  <div>
    <h2>Layout</h2>
    <my-main></my-main>
  </div>
</template>
<script>
  const myMain = {
    template: '#main',
    inject: ['msg', 'num', 'setNum', 'reactiveNum'],
    mounted () {
      this.setNum()
    }
  }
  const myLayout = {
    template: '#layout',
    components: {
      myMain
    }
  }
  const { createApp, computed } = Vue
  const app = createApp({
    components: {
      myLayout
    },
    data () {
      return {
        num: 10
      }
    },
    provide () {
      return {
        msg: 'hello',
        num: 1000,
        setNum () {
          console.log('1111111')
        },
        reactiveNum: computed(() => {
          return this.num + 10
        })
      }
    },
    mounted () {
      setTimeout(() => {
        this.num = 500
      }, 3000)
    }
  })
  app.config.unwrapInjectedRef = true
  app.mount('#root')
</script>
</html>